@extends('adminDialog')
@section('content')
    <form action="{{url('admin/users/updatelevels/'.$model->id)}}" method="POST" class="J_ajaxForm">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="pop_cont pop_table">
            <table width="100%">
                <tbody>
                <tr>
                    <th><label for="name">等级名称 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="name" id="name" class="input length_2" value="{{$model->name}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="start">等级消费上限 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="start" id="start" class="input length_2" value="{{$model->start}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="end">等级消费下限 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="end" id="end" class="input length_2" value="{{$model->end}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="avatar">等级图标</label></th>
                    <td>
                        <input type="hidden" name="icon" id="icon" value="{{intval($model->icon)}}"/>
                        <span id="upload_btn" class="cc"><img src="{{url('/img/level-'.intval($model->icon).'/50-50')}}"</span>
                        <div class="cc gray">建议 50px * 50px</div>
                    </td>
                </tr>

                </tbody>
            </table>
        </div>

        <div class="pop_bottom cc">
            <button type="reset" class="btn fr" id="J_dialog_close">取消</button>
            <button type="submit" class="btn btn_submit J_ajax_submit_btn fr mr10" id="J_dialog_close">提交</button>
        </div>
    </form>
@stop

@section('style')
    <style>
        .body_none {width: 320px;}
        #upload_btn {cursor:pointer; display: inline-block;}
    </style>
@stop

@section('js')
    @parent
    <script src="{{asset('/js/plupload/plupload.full.min.js')}}"></script>
    <script>
        var uploader = new plupload.Uploader({
            browse_button : 'upload_btn',
            url : '{{url('/upimg')}}',
            flash_swf_url : '{{asset('/js/plupload/Moxie.swf')}}',
            silverlight_xap_url: '{{asset('/js/plupload/Moxie.xap')}}',
            filters : {
                mime_types : [
                    {title: '图片文件', extensions: "jpg,gif,png"}
                ]
            },
            multi_selection : false,
            file_data_name  : 'file',
            multipart_params: {'_token': GV.TOKEN, 'dir': 'level'}
        });
        uploader.init();

        uploader.bind('Error', function (uploader, errObject) {
            Wind.dialog.alert(errObject.message);
        });

        uploader.bind('FilesAdded', function () {
            uploader.start();
        });
        uploader.bind('FileUploaded', function (uploader, file, responseObj) {
            var ret = $.parseJSON(responseObj.response);
            if (! ret.id)
                Wind.dialog.alert(ret.message);
            else {
                $('#icon').val(ret.id);
                $('#upload_btn').find('img').attr('src', '{!!url("img/level-' + ret.id + '/50-50")!!}');
            }
        });
    </script>
@stop